package org.smartopen.unionpay.openapi.listener;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.smartframework.unionpay.domain.SmartPayNotifyResult;
import org.smartframework.unionpay.domain.SmartRefundNotifyResult;
import org.smartframework.unionpay.event.PayNotifyEvent;
import org.smartframework.unionpay.event.RefundNotifyEvent;
import org.smartopen.unionpay.openapi.listener.mq.impl.UnionPayNotifyListener;
import org.smartopen.unionpay.openapi.listener.mq.impl.UnionPayRefundNotifyListener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 支付成功事件
 *
 * @author ycc
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class PayNotifyListener {

    private final UnionPayNotifyListener payNotify;
    private final UnionPayRefundNotifyListener refundNotify;

    @EventListener
    @Async
    public void notify(PayNotifyEvent event) {
        payNotify.sendMessage((SmartPayNotifyResult) event.getSource());
    }

    @Async
    @EventListener
    public void refundNotify(RefundNotifyEvent event) {
        refundNotify.sendMessage((SmartRefundNotifyResult) event.getSource());
    }
}
